package com.ks.cms.controller;


import com.ks.cms.controller.dto.CmsClassRequest;
import com.ks.cms.controller.dto.SearchCriteriaBase;
import com.ks.cms.entity.BCmsNews;
import com.ks.cms.service.IBCmsNewsService;
import com.ks.core.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 信息发布系统的新闻公告信息表 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-12-21
 */
@RestController
@RequestMapping("/bCmsNews")
@Api(value = "信息发布服务管理模块", description = "信息发布服务管理模块")
public class BCmsNewsController extends _ControllerBase {
    @Autowired
    private IBCmsNewsService bCmsNewsService;

    @PostMapping("/addBCmsNews")
    @ApiOperation(value = "信息发布添加接口", notes = "添加BCmsNews实体类所有信息")
    public Object addBCmsNews(@RequestBody BCmsNews bCmsNews) {
        int i = bCmsNewsService.addBCmsNews(getContext(), bCmsNews);
        return Result.success(i);

    }

    @PostMapping("/deleteBCmsNews")
    @ApiOperation(value = "信息发布删除接口", notes = "idList里面存放需要的id")
    public Object deleteBCmsNews(@RequestBody CmsClassRequest request) {
        int i = bCmsNewsService.deleteBCmsNews(getContext(), request.getIds());
        return Result.success(i);

    }

    @PostMapping("/updateBCmsNews")
    @ApiOperation(value = "信息发布修改接口", notes = "id字段里面存放查找条件,选择修改所需字段")
    public Object updateBCmsNews(@RequestBody BCmsNews bCmsNews) {
        int i = bCmsNewsService.updateBCmsNews(getContext(), bCmsNews);
        return Result.success(i);

    }

    @PostMapping("/selectBCmsNews")
    @ApiOperation(value = "信息发布列表查询接口", notes = "利用分页查询查询表中的数据")
    public Object selectBCmsNews(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> resultMap = bCmsNewsService.selectBCmsNews(getContext(), searchCriteriaBase);
        return Result.success(resultMap);
    }

    @PostMapping("/selectAdminBCmsNews")
    @ApiOperation(value = "系统后台信息发布列表查询接口", notes = "系统后台信息发布列表查询接口")
    public Object selectAdminBCmsNews(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> resultMap = bCmsNewsService.selectAdminBCmsNews(getContext(), searchCriteriaBase);
        return Result.success(resultMap);
    }


    @PostMapping("/selectBannerList")
    @ApiOperation(value = "小程序端轮播图列表查询接口", notes = "小程序端轮播图列表查询接口")
    public Object selectBannerList() {
        List<BCmsNews> bCmsNewsList = bCmsNewsService.getBCmsNewsList(getContext());
        return Result.success(bCmsNewsList);
    }




    @PostMapping("/selectBCmsNewsList")
    @ApiOperation(value = "小程序端信息发布列表查询接口", notes = "利用分页查询查询表中的数据")
    public Object selectBCmsNewsList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> resultMap = bCmsNewsService.selectBCmsNewsList(getContext(), searchCriteriaBase);
        return Result.success(resultMap);
    }

    @PostMapping("/selectInfoBCmsNews")
    @ApiOperation(value = "信息发布服务信息详情查询接口", notes = "信息发布服务信息详情查询接口")
    public Object selectInfoBCmsNews(@RequestBody CmsClassRequest request) {
        BCmsNews cmsNews = bCmsNewsService.selectInfoBCmsNews(getContext(), request.getId());
        return Result.success(cmsNews);
    }

    @PostMapping("/changeBCmsNewsState")
    @ApiOperation(value = "信息发布服务信息状态变更接口", notes = "id字段存放id，cState字段存放状态码")
    public Object changeBCmsNewsState(@RequestBody CmsClassRequest request) {
        int i = bCmsNewsService.changeBCmsNewsState(getContext(), request.getId(), request.getState());
        return Result.success(i);
    }

    @PostMapping("/addCmsCount")
    public int addCmsCount(@RequestParam int id, @RequestParam int type) {
        int i = bCmsNewsService.addCount(id, type);
        return i;
    }
}

